package com.parktech.sun.web.controller;

import com.parktech.sun.domain.model.Constants;
import com.parktech.sun.domain.repository.Page;
import com.parktech.sun.domain.service.industryservice.IndustryServiceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * User: Think
 * Date: 11-1-18
 * Time: 上午1:05
 */
@Controller
@RequestMapping("/industryservices")
public class IndustryServiceViewController extends BaseViewController {
    
    private int pageSize = Constants.PAGINATION_PAGE_SIZE;

    private IndustryServiceService industryServiceService;

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    @Autowired
    public IndustryServiceViewController(IndustryServiceService industryServiceService) {
        this.industryServiceService = industryServiceService;
    }

    @RequestMapping("/{industryServiceId}")
    public String viewCategory(@PathVariable("industryServiceId") Long industryServiceId, Model model) {
        model.addAttribute(industryServiceService.getById(industryServiceId));
        model.addAttribute("subCategoryList", industryServiceService.getWithSubCategoryAndTop4Info(industryServiceId));
        return "industryServices";
    }

    @RequestMapping("/{industryServiceId}/{subCategoryId}/pages/{pageNo}")
    public String viewSubCategory(@PathVariable("industryServiceId") Long industryServiceId,
                                  @PathVariable("subCategoryId") Long subCategoryId,
                                  @PathVariable("pageNo") int pageNo, Model model) {

        Page page = new Page(pageSize, pageNo);
        model.addAttribute(industryServiceService.getById(industryServiceId));
        model.addAttribute(industryServiceService.getByCategoryId(subCategoryId));
        model.addAttribute("subCategoryList", industryServiceService.searchCategory(null, industryServiceId, new Page(1000, 1)).getResult());
        model.addAttribute(industryServiceService.pageInfoBy(industryServiceId, subCategoryId, page));
        return "industryServiceSubList";
    }

    @RequestMapping("/industryservice/{industryServiceId}")
    public String viewDetail(@PathVariable("industryServiceId") Long industryServiceId, Model model) {
        model.addAttribute(industryServiceService.getById(industryServiceId));
        return "industryServiceDetail";
    }
    @RequestMapping("/informations/{industryServiceInfoId}")
    public String viewInfoDetail(@PathVariable("industryServiceInfoId") Long industryServiceInfoId, Model model) {
        model.addAttribute(industryServiceService.getInformationById(industryServiceInfoId));
        return "industryServiceInfoDetail";
    }
}
